/**
 * 斗地主
 * @author Troj.an
 *
 */
class DDZGameSceneView extends V.GameView
{
    public moneyLabel: eui.BitmapLabel;
    public player1: DDZPlayerView;
    public player2: DDZPlayerView;
    public player0: DDZPlayerView;
    public readyIcon: eui.Image;
    public cardList: how.poker.CardList;
    public clockGroup: eui.Group;
    public clockLabel: eui.Label;
    public callGroup: eui.Group;
    public operateGroup: eui.Group;
    public callButton: how.Button;
    public noCallButton: how.Button;
    private cardData: eui.ArrayCollection;
    public promptButton: how.Button;
    public noPutButton: how.Button;
    public putButton: how.Button;
    public lordCardList: eui.List;
    public roundLabel: eui.BitmapLabel;
    public beishuLabel: eui.BitmapLabel;
    public putCardList: eui.List;
    public trustButton: how.Button;
    public trustGroup: eui.Group;
    public cancelTrustButton: how.Button;
    public quitButton: how.Button;
    public chatButton: how.Button;
    public addMoneyButton: eui.Group;
    public addZuanshiButton: eui.Group;
    public goldLabel: eui.BitmapLabel;
    public taskButton: how.Button;
    public settingButton: how.Button;
    public gameEffectPanel: DDZGameEffectPanel;
    public timeLabel: eui.Label;
    public bigLrdCardList: eui.List;
    public noticeGroup: eui.Group;
    public jiangliLabel: eui.Label;
    public jiangliGroup: eui.Group;
    public addIcon: how.Button;
    public activityButton: how.Button;
    public bcImg: eui.Image;
    public beishuIcon: eui.BitmapLabel;
    public readyButton: how.Button;
    public roomIDLabel: eui.BitmapLabel;
    public inviteButton: how.Button;
    public macButton: how.Button;
    public radioGroup: eui.Group;
    public radioTimeLabel: eui.Label;
    public obButton: how.Button;
    public gameOverPanel: eui.Panel;
    public gameOverUI: eui.Component;

    protected radioTime: number = 0;
    protected radioBegin = false;
    public canPrompt: boolean = false;
    private isCalling: boolean = false;//是否在叫地主阶段
    private clockTimeID: number;
    private time: number;
    private isMyCall: boolean = false;
    private trueCardList: any[];
    private currentPromptIndex: number;
    private canNoPut: boolean;
    private lastPutChair:number = -1;

    /**
     * 最后一次出的牌
     */
    private lastCards: number[] = [];

    public constructor() 
    {
        super();
        this.MAX_PLAYER = 3;
        this.skinName = "DDZGameSceneViewSkin";
        this.Res = DataConfig.ResConfig[DataConfig.KIND_ID_DDZ3P];
    }

    protected childrenCreated(): void 
    {
        this.initPlayer();

        this.inviteButton.visible = false;
        this.readyIcon.visible = false;
        this.readyButton.visible = false;
        this.cardList.visible = false;
        this.clockGroup.visible = false;
        this.callGroup.visible = false;
        this.operateGroup.visible = false;
        this.cardList.dragPutEnabled = false;
        this.beishuIcon.visible = false;
        this.macButton.visible = false;
        this.lordCardList.dataProvider = null;
        this.bigLrdCardList.dataProvider = null;
        this.roundLabel.text = "-1";
      
        this.cardList.addEventListener(how.poker.CardList.POPUP_CHANGED, this.onCardListPopChanged, this);
        this.callButton.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onCallButton, this);
        this.noCallButton.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onNoCallButton, this);
        this.promptButton.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onPromptButton, this);
        this.putButton.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onPutButton, this);
        this.noPutButton.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onNoPutButton, this);
        this.gameOverUI["goonButton"].addEventListener(egret.TouchEvent.TOUCH_TAP, this.onGameGoon, this);
        this.quitButton.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onGameQuit, this)
    }

    /** 收到网络消息 */
    public onNetData(s:number, d:any):void
    {
        switch(s)
        {
            case 100: // 开始发牌
            {
                this.onSendCard(d);
                break;
            }
            case 101: // 开始叫分
            {
                for(var i = 0; i < this.playerList.length; ++i)
                {
                  (this.playerList[i] as DDZPlayerView).onPlayerCall(d, false);
                }
                this.onPlayerCall(d, false);
                break;
            }
            case 109: // 抢地主
            {
                for(var i = 0; i < this.playerList.length; ++i)
                {
                  (this.playerList[i] as DDZPlayerView).onPlayerCall(d, true);
                }
                this.onPlayerCall(d, true);
                break;
            }
            case 102: // 游戏开始
            {

                this.onGameStart(d);
                break;
            }
            case 103: // 出牌
            {
                for(var i = 0; i < this.playerList.length; ++i)
                {
                  (this.playerList[i] as DDZPlayerView).onPlayerPut(d);
                }
                this.onPlayerPut(d);
                break;
            }
            case 104: // 不出
            {
                for(var i = 0; i < this.playerList.length; ++i)
                {
                  (this.playerList[i] as DDZPlayerView).onPlayerPass(d);
                }
                this.onPlayerPass(d);
                break;
            }
            case 105: // 游戏结束
            {
                this.onGameOver(d);
                break;
            }
            case 106: // 明牌开始
            {
                for(var i = 0; i < this.playerList.length; ++i)
                {
                  (this.playerList[i] as DDZPlayerView).onBrightCard(d);
                }
                this.onBrightCard(d);
                break;
            }
        }
    }

    public onSyncData(d:any):void
    {
        let gameStatus = D.App.table.gameStatus;

        if(gameStatus == 100)
        {
            // {
            // "bLandScore":0,
            // "wCurrentUser":0,
            // "lBaseScore":10,
            // "bBrightTime":1,
            // "bScoreInfo":[0,0,0],
            // "bCardData":[26,9,23,34,10,56,55,54,45,36,22,5,52,11,2,51,61,0,0,0],
            // "bUserTrustee":[0,0,0]
            // }
            this.showPlayer(65535); //这里暂时这样用一下显示所有玩家
            base.Utils.removes(d.bCardData, 0);
            this.onSendCard(d, true);

        }
        else if(gameStatus == 103)
        {
            // {
            //     "wBombTime":1,
            //     "wLandUser":1,
            //     "wCurrentUser":0,
            //     "wLastOutUser":2,
            //     "bLandScore":3,
            //     "bTurnCardCount":1,
            //     "lBaseScore":10,
            //     "bBrightTime":1,
            //     "bBrightCard":0,
            //     "bBackCard":[41,39,35],
            //     "bCardCount":[11,10,15],
            //     "bTurnCardData":[26,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
            //     "bCardData":[79,78,34,18,17,60,44,28,12,41,27,11,41,35,41,56,39,22,5,35],
            //     "bUserTrustee":[0,0,0],
            //     "BrightCard":[0]
            // }
            this.showPlayer(65535); //这里暂时这样用一下显示所有玩家
            this.onSendCard(d, true);
            for(var i = 0; i < this.playerList.length; ++i)
            {
                (this.playerList[i] as DDZPlayerView).onSyncData(d);
            }
            // 展示地主牌
            this.lordCardList.visible = true;
            this.lordCardList.dataProvider = new eui.ArrayCollection(d.bBackCard);
            this.timeLabel.visible = false;
            // 设置当前操作
            if (d.wCurrentUser == this.player0.chairId)
            {
                //如果轮到自己出牌了
                var canNoPut: boolean = true;
                this.canNoPut = true;
                if (this.canNoPut) 
                {
                    //如果我的牌不是最大
                    this.tip(this.lastCards);
                }
                else 
                {
                    this.lastCards = [];
                    this.tip([]);
                }
                this.onOperate(false, false, canNoPut);
            }
            this.lastPutChair = d.wLastOutUser;
        }
    }

    protected initView(): void
    {
        this.cardList["lordCards"] = null;
        this.timeLabel.visible = true;
        this.readyIcon.visible = false;
        this.cardList.setPopUpIndices();
        this.cardList.visible = false;
        this.cardList.dataProvider = null;
        this.lordCardList.dataProvider = null;
    }

    public setLordCard(card: string, index: number): void
    {
        var cardList: eui.ArrayCollection = this.lordCardList.dataProvider as eui.ArrayCollection;
        cardList.replaceItemAt(card, index);
        if (index == 2)
        {
            this.lordCardList.visible = true;
        }
    }

    public onSendCard(data: any, isReconnect: boolean = false): void 
    {
        this.gameOverPanel.visible = false;
        this.canPrompt = true;
        this.inviteButton.visible = this.inviteButton.includeInLayout = false;
        this.roundLabel.text = "-1";
        this.timeLabel.visible = true;
        this.cardList["lordCards"] = null;
        this.readyButton.visible = this.readyButton.includeInLayout = this.readyIcon.visible = false;
        this.cardList.visible = true;
        this.cardList.selectedItem = null;
        this.cardList.setPopUpIndices();
        this.cardList.dragPutEnabled = false;
        this.lordCardList.dataProvider = new eui.ArrayCollection(["", "", ""]);
        this.lordCardList.visible = false;
        this.bigLrdCardList.dataProvider = null;
        this.beishuLabel.text = "1";
        this.beishuIcon.text = "x1";
        if (!isReconnect && data.bCardData) 
        {
            this.setMyCards(data.bCardData);
        }
        else 
        {
            how.poker.CardLogic_DDZ3.sortByCardData(data.bCardData);
            this.cardList.dataProvider = this.cardData = new eui.ArrayCollection(data.bCardData);
        }
        this.putCardList.dataProvider = null;
        for(var i = 0; i < this.playerList.length; ++i)
        {
            (this.playerList[i] as DDZPlayerView).setGameStartUI(null);
        }
        //如果轮到自己操作
        if (data.wCurrentUser == this.player0.chairId)
        {
            this.onOperate(true, false);
        }
    }

    public onOperate(isCall: boolean, isRob: boolean, canNoPut: boolean = true, remainTime: number = -1): void 
    {
        this.isCalling = isCall;
        var time: number = isCall ? GameConfig.callTime : GameConfig.putCardTime;
        if (remainTime != -1)
        {
            time = remainTime;
        }
        this.startClock(time);
        this.callGroup.visible = isCall;
        if (isRob) 
        {
            this.callButton["iconImg"].source = "ddz_qiangdizhuicon_png";
            this.noCallButton["iconImg"].source = "ddz_buqiangicon_png";
        }
        else 
        {
            this.callButton["iconImg"].source = "ddz_jiaodizhuicon_png";
            this.noCallButton["iconImg"].source = "ddz_bujiaoicon_png";
        }
        this.operateGroup.visible = !isCall;
        this.noPutButton.includeInLayout = this.noPutButton.visible = canNoPut;
        this.cardList.dragPutEnabled = !isCall;
        this.readyIcon.visible = false;
        if (!isCall) 
        {
            this.onCardListPopChanged();
            this.putCardList.dataProvider = null;
        }
    }

    public setMyCards(cards: string[]): void 
    {
        this.cardList.dataProvider = this.cardData = new eui.ArrayCollection();
        this.addMyCard(cards, 0);
        how.SoundManager.playEffect(SoundConfig.GAME_FAPAI);
    }

    public addMyCard(cards: string[], index: number): void 
    {
        if (index < cards.length) 
        {
            this.cardData.addItem(cards[index]);
            egret.Tween.get(this.cardList).wait(90).call(this.addMyCard, this, [cards, index + 1]);
        }
        else 
        {
            how.poker.CardLogic_DDZ3.sortByCardData(this.cardData.source);
            this.cardData.refresh();
        }
    }

    private onPlayerCall(data1: any, isRob): void 
    {
        var isCall = data1.bLandScore == 1;
        this.onIntegral(data1.bCurrentScore);
        var operateChair = data1.bLandUser;
        if(isRob)
        {
            operateChair = data1.wDoubleUser;
            isCall = data1.bDoubleScore == 1;
        }
        if (operateChair == this.player0.chairId) 
        {
            if (!this.isMyCall)
            {
                this.onCall(isCall, isRob);
            }
            this.isMyCall = false;
            this.onOperateOver();
        }

        if (data1.wCurrentUser == this.player0.chairId) //如果轮到自己叫地主
        {
            this.onOperate(true, isRob);
        }
    }

    public onGameStart(d: any): void
    {
        
    }

    public onBrightCard(d: any): void
    {
        var isLord: boolean = d.wBrightUser == this.player0.chairId;
        var isRob = false;
        if (isLord) 
        {
            this.onOperate(false, isRob, false, GameConfig.lordPutCardTime);
        }
        this.isCalling = false;

        this.onLord(d, isLord);

        // 待修改 this["player0"].setLordUI(false);
        var lordSeat = this.c2p(d.wBrightUser);
        (this.playerList[lordSeat] as DDZPlayerView).setLordUI(this.playerList[lordSeat].getData());

        if (isLord) 
        {
            WebSocketInstance.getHallSocket().send("9,6", {bIsBright:false});
            this.lastCards = [];
            this.tip([]);
        }
    }


    private tip(cards: number[]): void
    {
        if (this.cardList.dataProvider)
        {
            var myCardData: number[] = (this.cardList.dataProvider as eui.ArrayCollection).source;
            var logic = how.poker.CardLogic_DDZ3;
            var tipResult = logic.tip(myCardData, cards);
            this.trueCardList = [];
            for (var i = 0; i < tipResult.length; i++)
            {
                this.trueCardList.push({ cards: tipResult[i] });
            }
            this.trueCardList.reverse();
            this.currentPromptIndex = this.trueCardList.length - 1;
        }
    }

        /**
     * 确定地主
     */
    public onLord(d: any, isLord: boolean, needAdd: boolean = true): void 
    {
        this.beishuIcon.visible = false;
        var cards = d.bBackCardData || d.cards;
        if (isLord) {
            if (needAdd) {
                cards = cards || [];
                var myCardSource = this.cardData ? (this.cardData.source || []) : [];
                var newCardSource: number[] = myCardSource.concat(cards);
                how.poker.CardLogic_DDZ3.sortByCardData(newCardSource);
                this.cardData = new eui.ArrayCollection(newCardSource);
                this.cardList["lordCards"] = cards;
                this.canPrompt = true;
                this.cardList.dataProvider = this.cardData;
                // this.cardList.horizontalCenter = 0;
            }
            this.player0.isLordIcon.source = isLord ? "ddz_dizhu_png" : "ddz_nongming_png";
        }
        if (needAdd) {
            this.bigLrdCardList.dataProvider = new eui.ArrayCollection(cards);
            this.timeLabel.visible = false;
        }
        else {
            this.lordCardList.visible = true;
            this.lordCardList.dataProvider = new eui.ArrayCollection(cards);
            this.timeLabel.visible = false;
            this.bigLrdCardList.dataProvider = null;
        }
        this.readyIcon.visible = false;
    }

    private onPlayerPut(d: any): void 
    {
        // if (data.integral) {
        //     this.onIntegral(data.integral);
        // }
        var current: number =   d.wCurrentUser;
        this.lastCards = !d.bCardData ? this.lastCards : d.bCardData;
        if (d.wOutCardUser == this.player0.chairId) 
        {
            //如果是自己出的牌
            this.onOperateOver();
        }
        var playerData = this.getPlayerData(d.wOutCardUser);
        this.playPutSound(!!d.bCardData, playerData.gender, how.poker.CardLogic_DDZ3.getCardType(this.lastCards));

        if (current == this.player0.chairId)
        {
            //如果轮到自己出牌了
            var canNoPut: boolean = true;
            this.canNoPut = true;
            if (this.canNoPut) 
            {
                //如果我的牌不是最大
                this.tip(this.lastCards);
            }
            else 
            {
                this.lastCards = [];
                this.tip([]);
            }
            this.onOperate(false, false, canNoPut);
        }
        this.lastPutChair = d.wOutCardUser;
    }

    /**
     * 操作结束
     */
    public onRoundOver(): void {
        // this.callUI("onRoundOver");
    }

    /**
     * 倍数变化
     */
    public onIntegral(integral: number): void 
    {
        DDZGameSceneData.getInstance().integral = integral;
        this.beishuLabel.text = integral + "";
        if (this.isCalling) 
        {
            if (this.beishuIcon.text != "x" + integral || !this.beishuIcon.visible) 
            {
                this.beishuIcon.text = "x" + integral;
                this.beishuIcon.scaleX = this.beishuIcon.scaleY = 0;
                egret.Tween.get(this.beishuIcon).to({ scaleX: 1, scaleY: 1 }, 300, egret.Ease.bounceOut);
            }
            this.beishuIcon.visible = true;
        }
    }


    private startClock(startTime: number): void {
        this.time = startTime;
        this.stopClock();
        this.clockGroup.visible = true;
        this.clockLabel.text = startTime + "";
        this.clockTimeID = egret.setInterval(this.onClock, this, 1000);
    }

    private onClock(): void {
        var current: number = parseInt(this.clockLabel.text);
        if (current > 1) {
            this.clockLabel.text = current - 1 + "";
            if (current - 1 < 4) {//从倒数第三秒开始
                // how.Application.notify("轮到您操作了！", "欢乐斗地主");
                // how.Application.vibrationScreen();
                how.SoundManager.playEffect(SoundConfig.GAME_REMIND);
            }
        }
        else {
            this.onClockOver();
        }
    }

        /**
    * 倒计时结束
    */
    public onClockOver(): void {
        this.stopClock();
        this.startClock(this.time);
    }

    private stopClock(): void {
        egret.clearInterval(this.clockTimeID);
        this.clockGroup.visible = false;
    }

    

    public canPut(canPut: boolean): void {
        this.putButton.enabled = canPut;
    }

    public onCall(isCall: boolean, isRob: boolean): void 
    {
        var jiaodizhuSource = !isRob ? "ddz_jiaodizhu_png" : "ddz_qiangdizhu_png";
        var buqiangSource = !isRob ? "ddz_bujiao_png" : "ddz_buqiang_png";
        this.readyIcon.source = isCall ? jiaodizhuSource : buqiangSource;
        this.readyIcon.visible = true;
    }


    public onOperateOver(): void 
    {
        this.trueCardList = null;
        this.currentPromptIndex = -1;

        this.stopClock();
        this.callGroup.visible = false;
        this.operateGroup.visible = false;
        this.cardList.dragPutEnabled = false;
    }

    public onPopCard(cards: string[]): void 
    {
        this.cardList.popupedItems = cards;
    }

    public onPutCard(cards: number[], needRemove: boolean = true, isReconnect: boolean = false): void 
    {
        if (cards) 
        {
            if (needRemove) 
            {
                var data: eui.ArrayCollection = this.cardList.dataProvider as eui.ArrayCollection;
                for (var i: number = 0; i < cards.length; i++) {
                    data.removeItemAt(data.getItemIndex(cards[i]));
                }
                this.cardList.setPopUpIndices();//刷新弹起项
                // if (this.cardData.length == 20) {
                //     this.cardList.horizontalCenter = 70 - 70 / 4;
                // }
                // if (this.cardData.length == 19) {
                //     this.cardList.horizontalCenter = 70 - 70 / 3;
                // }
                // if (this.cardData.length == 18) {
                //     this.cardList.horizontalCenter = 70 - 70 / 2;
                // }
                // else {
                //     this.cardList.horizontalCenter = 0;
                // }
                var toBottom = this.putCardList.bottom;
                this.putCardList.bottom = 150;
                egret.Tween.get(this.putCardList).to({ bottom: toBottom }, 300);
            }
            this.putCardList.dataProvider = new eui.ArrayCollection(cards);
            this.readyIcon.visible = false;
            if (!isReconnect) {
                how.SoundManager.playEffect(SoundConfig.GAME_CHUPAI);
            }
        }
        else {
            this.putCardList.dataProvider = null;
            this.readyIcon.visible = true;
            this.readyIcon.source = "ddz_buchu_png";
        }
    }

    public onPlayerPass(d: any): void
    {
        if (d.bNewTurn == 1) 
        {
            //如果一轮结束
            this.onRoundOver();
            this.lastCards = [];
        }
        // if (data.integral) {
        //     this.onIntegral(data.integral);
        // }
        var current: number =   d.wCurrentUser;
        if (d.wPassUser == this.player0.chairId) 
        {
            //如果是自己出的牌
            this.onOperateOver();
        }
        var playerData = this.getPlayerData(d.wPassUser);
        this.playPutSound(false, playerData.gender, null);

        if (current == this.player0.chairId)
        {
            //如果轮到自己出牌了
            var canNoPut: boolean = true;
            this.canNoPut = true;

            if (this.lastPutChair == this.player0.chairId) 
            {
                //如果我的牌最大
                this.canNoPut = canNoPut = false;
            }

            if (this.canNoPut) 
            {
                //如果我的牌不是最大
                this.tip(this.lastCards);
            }
            else 
            {
                this.lastCards = [];
                this.tip([]);
            }
            this.onOperate(false, false, canNoPut);
        }
    }

    private onGameOver(data: any): void 
    {
        // this.tdata.clonePlayerList();
        this.currentPromptIndex = -1;
        this.lastCards = [];
        this.isCalling = false;
        this.cardList["lordCards"] = null;
        this.timeLabel.visible = true;
        this.readyIcon.visible = false;
        this.cardList.setPopUpIndices();
        this.cardList.visible = false;
        this.cardList.dataProvider = null;
        this.lordCardList.dataProvider = null;
        this.onOperateOver();

        if (data.Spring == 1) 
        {
            how.SoundManager.playEffect(SoundConfig.GAME_CARDTYPE_CHUNTIAN);
            this.gameEffectPanel.playChuntian((): void => {
                this.showGameOver(data);
            }, this);
        }
        else 
        {
            egret.Tween.get(this).wait(1000).call(this.showGameOver, this, [data]);
        }
    }

    private showGameOver(data: any): void 
    {
        this.gameOverPanel.visible = true;
        for(var i = 0; i < data.lGameScore.length; ++i)
        {
            var seat = this.c2p(i);
            var playerView: V.PlayerView = this.playerList[seat];
            this.gameOverUI["player"+i].text = playerView.getData().nickName;
            this.gameOverUI["beishu"+i].text = 3 * data.wBombTime;
            this.gameOverUI["defen"+i].text = data.lGameScore[i];
        }
        egret.Tween.removeAllTweens();
    }

    private onGameGoon(data: any):void
    {
        this.gameOverPanel.visible = false;
    }

    private onGameQuit(data: any):void
    {
        WebSocketInstance.getHallSocket().send(CMDConfig.SEND_LEAVE_GAME, {});
        WebSocketInstance.getHallSocket().send(CMDConfig.SEND_LEAVE_ROOM, {});
    }

    private playPutSound(isPut: boolean, sex: number, currentCardType: { type: how.poker.CardType, value: number }): void {
        var sexString = sex == 1 ? "Man" : "Woman";
        if (isPut) {//如果上家是出了牌
            var cardValue = how.poker.CardLogic_DDZ3.getCardValue(currentCardType.value);
            if (currentCardType.type == how.poker.CardType.Single) {//单张
                how.SoundManager.playEffect(how.StringUtils.format(SoundConfig.GAME_CARDTYPE_SINGLE_CALL, sexString, cardValue));
            }
            if (currentCardType.type == how.poker.CardType.Double) {//对子
                how.SoundManager.playEffect(how.StringUtils.format(SoundConfig.GAME_CARDTYPE_DOUBLE_CALL, sexString, cardValue));
            }
            if (currentCardType.type == how.poker.CardType.Treble) {//三张
                how.SoundManager.playEffect(how.StringUtils.format(SoundConfig.GAME_CARDTYPE_TREBLE_CALL, sexString, cardValue));
            }
            if (currentCardType.type == how.poker.CardType.TrebleAndOne) {//三带一
                how.SoundManager.playEffect(how.StringUtils.format(SoundConfig.GAME_CARDTYPE_TREBLE_ONE_CALL, sexString));
            }
            if (currentCardType.type == how.poker.CardType.TrebleAndTwo) {//三带二
                how.SoundManager.playEffect(how.StringUtils.format(SoundConfig.GAME_CARDTYPE_TREBLE_TWO_CALL, sexString));
            }
            if (currentCardType.type == how.poker.CardType.FourfoldAndSingle) {//四带二
                how.SoundManager.playEffect(how.StringUtils.format(SoundConfig.GAME_CARDTYPE_FOURFOLD_TWO_CALL, sexString));
            }
            if (currentCardType.type == how.poker.CardType.FourfoldAndDouble) {//四带两对
                how.SoundManager.playEffect(how.StringUtils.format(SoundConfig.GAME_CARDTYPE_FOURFOLD_TWODOUBLE_CALL, sexString));
            }
            if (currentCardType.type == how.poker.CardType.DoubleLine) {//连对
                how.SoundManager.playEffect(how.StringUtils.format(SoundConfig.GAME_CARDTYPE_DOUBLELINE_CALL, sexString));
                how.SoundManager.playEffect(SoundConfig.GAME_CARDTYPE_SHUNZI);
                this.gameEffectPanel.playLiandui();
            }
            if (currentCardType.type == how.poker.CardType.SingleLine) {//顺子
                how.SoundManager.playEffect(how.StringUtils.format(SoundConfig.GAME_CARDTYPE_SINGLELINE_CALL, sexString));
                how.SoundManager.playEffect(SoundConfig.GAME_CARDTYPE_SHUNZI);
                this.gameEffectPanel.playShunzi();
            }
            if (currentCardType.type == how.poker.CardType.Boom) {//炸弹
                how.SoundManager.playEffect(how.StringUtils.format(SoundConfig.GAME_CARDTYPE_BOOM_CALL, sexString));
                how.SoundManager.playEffect(SoundConfig.GAME_CARDTYPE_BOOM);
                this.gameEffectPanel.playZhadan();
            }
            if (currentCardType.type == how.poker.CardType.Rocket) {//火箭
                how.SoundManager.playEffect(how.StringUtils.format(SoundConfig.GAME_CARDTYPE_ROCKET_CALL, sexString));
                how.SoundManager.playEffect(SoundConfig.GAME_CARDTYPE_ROCKET);
                this.gameEffectPanel.playHuojian();
            }
            if (
                currentCardType.type == how.poker.CardType.Plane ||
                currentCardType.type == how.poker.CardType.PlaneAndSingle ||
                currentCardType.type == how.poker.CardType.PlaneAndDouble) {//飞机
                how.SoundManager.playEffect(how.StringUtils.format(SoundConfig.GAME_CARDTYPE_PLANE_CALL, sexString));
                how.SoundManager.playEffect(SoundConfig.GAME_CARDTYPE_PLANE);
                this.gameEffectPanel.playFeiji();
            }
        }
        else {
            how.SoundManager.playEffect(how.StringUtils.format(SoundConfig.GAME_CARDTYPE_NOTPUT_CALL, sexString, Math.round(how.Random.range(1, 4))));
        }
    }

    /////// 按钮事件 /////////
    private onCardListPopChanged(value: any = null): void 
    {
        if (this.lastCards.length) 
        {
            var tipResult = how.poker.CardLogic_DDZ3.tip(this.cardList.popupedItems, this.lastCards);
            var type = how.poker.CardLogic_DDZ3.getCardType(this.cardList.popupedItems);
            this.canPut(tipResult.length == 1 && tipResult[0].length == this.cardList.popupedItems.length) || type.type == how.poker.CardType.Rocket || (type.type == how.poker.CardType.Boom && tipResult.length > 0);
        }
        else 
        {
            this.canPut(how.poker.CardLogic_DDZ3.getCardType(this.cardList.popupedItems).type != how.poker.CardType.Error);
        }
        if (value && value.data.length) 
        {
            how.SoundManager.playEffect(SoundConfig.GAME_SELECTCARD);
        }
    }

    private onCallButton(): void 
    {
        this.isMyCall = true;
        this.onCall(true, null);
        this.onOperateOver();
        WebSocketInstance.getHallSocket().send(CMDConfig.DDZ_SEND_CALLSCORE, {bLandScore:1});
    }

    private onNoCallButton(): void 
    {
        this.isMyCall = true;
        this.onCall(false, null);
        this.onOperateOver();
        WebSocketInstance.getHallSocket().send(CMDConfig.DDZ_SEND_CALLSCORE, {bLandScore:0});
    }

    private onPromptButton(): void 
    {
        if (this.canPrompt) 
        {
            if (this.trueCardList && this.trueCardList.length) 
            {
                this.onPopCard(this.trueCardList[this.currentPromptIndex].cards);
                if (this.currentPromptIndex == 0) 
                {
                    this.currentPromptIndex = this.trueCardList.length - 1;
                }
                else {
                    this.currentPromptIndex--;
                }
            }
            else 
            {
                //没有大于上家的牌
                if (this.canNoPut) 
                {
                    //如果可以不出
                    this.onNoPutButton();//直接不出
                }
                else 
                {
                    // var myCardData: string[] = (this.tgui.cardList.dataProvider as eui.ArrayCollection).source;
                    // this.callUI("onPopCard", [myCardData[myCardData.length - 1]]);
                }
            }
        }
    }

    private onPutButton(): void 
    {
        // this.report("onPutButton", this.cardList.popupedItems);
        var cards = this.cardList.popupedItems;
        var cardType = how.poker.CardLogic_DDZ3.getCardType(cards);
        if (cardType.type == how.poker.CardType.Error) {
            this.onPutCard(null);
        }
        else {
            this.onOperateOver();
            this.onPutCard(cards);
            WebSocketInstance.getHallSocket().send(CMDConfig.DDZ_PLAY_CARD, cards);
            
        }
        this.playPutSound(true, this.player0.getData().gender, how.poker.CardLogic_DDZ3.getCardType(cards));
    }

    private onNoPutButton(): void 
    {
        this.onOperateOver();
        // this.socket.send(CmdConfig.PUT, { cards: null });
        WebSocketInstance.getHallSocket().send(CMDConfig.DDZ_PASS_CARD, {});
        this.playPutSound(false, this.player0.getData().gender, null);
        this.onPutCard(null);
    }
}